package com.JFapp.utils;

import com.JFapp.domain.entity.LoginUser;
import com.JFapp.service.RoleService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {



    /**
     * 获取用户
     */

    public static LoginUser getLoginUser(){
        return (LoginUser) getAuthentication().getPrincipal();
    }

    /**
     * 获取Authentication
     * @return
     */
    private static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 判断是否为超级用户
     * @return
     */
    public static Boolean isAdmin(){
        Long id = getLoginUser().getUser().getId();
        return id!=null && 1l==id;
    }



    /**
     * 获取id
     */
    public static Long getUserId(){
        return getLoginUser().getUser().getId();
    }
}
